// src/store/slice/reply.ts
import { createEntityAdapter, createSlice, Draft, EntityState, PayloadAction } from "@reduxjs/toolkit";
import { AppState } from "@store/index";

const replyCommentsAdapter = createEntityAdapter({
  selectId: (state:any) => state.com_id,
});

const { reducer: replyReducer, actions } = createSlice({
  name: "replyComments",
  initialState: replyCommentsAdapter.getInitialState(),
  reducers: {
    // 保存评论回复列表
    saveReplyComments: replyCommentsAdapter.addMany,
    // 清空评论回复列表
    clearReplyComments: replyCommentsAdapter.removeAll,
  },
});

// 用于获取评论回的状态选择器
export const replySelectors = replyCommentsAdapter.getSelectors<AppState>(
  (state) => state.replyReducer
);
// 导出和评论回复相关的 action creator 函数
export const { saveReplyComments, clearReplyComments } = actions;
// 导出用于管理评论回复的 reducer 函数
export default replyReducer;